interface BaseMessage<T extends string, D> {
  id?: string;
  type: T;
  data: D;
}

type ToolCallsMessage = BaseMessage<'toolCalls', ToolCall[]>;
export type ToolCallsResultMessage = BaseMessage<
  'toolCallsResult',
  ToolCallResult[]
>;
type HelloMessage = BaseMessage<'hello', { welcome: string }>;
type PingMessage = BaseMessage<'ping', { timestamp: number }>;
type InitializeMessage = BaseMessage<'initialize', { sessionId: string }>;
export type Message =
  | InitializeMessage
  | PingMessage
  | HelloMessage
  | ToolCallsMessage
  | ToolCallsResultMessage;

export interface ToolCall {
  id: string;
  type: 'function';
  function?: FunctionCall;
}

export interface ToolCallResult {
  id: string;
  ok: boolean;
}

interface FunctionCall {
  /** Function name */
  name: string;
  /** Function arguments */
  args: Record<string, string>;
}

/**
 * @param type  消息类型
 * @param actions  UI操作指令列表
 * @param message  给用户的反馈消息
 */
export type SocketMessageType = Message;
